
#include<iostream>
using namespace std;

const int MaxSize=10;
const int MaxQNode=10;

typedef struct node{
    int data;
    node *next;
}QNode;

void Insert(QNode *QH[],QNode *QT[],int x){
    QNode *s;
    s=new QNode;
    s->data=x;
    s->next=NULL;
    if(QH[x]==NULL){
        QH[x]=s;
        QT[x]=s;
    }
    else{
        QT[x]->next=s;
        QT[x]=s;
    }
}

void Create(QNode *QH[],QNode* QT[]){
    int n,x,i;
    cout<<"input n(n<10): ";
    cin>>n;
    cout<<endl;

    for(i=0;i<n;i++){
        do{
            cout<<"input no."<<i+1<<" number:";
            cin>>x;
        }while(x<0||x>10);
        Insert(QH,QT,x);
    }
}

void Link(QNode *QH[],QNode*QT[]){
    QNode*head,*tail;
    QNode*p;
    int first=1,i;
    for(i=0;i<MaxQNode;i++){
        if(QH[i]!=NULL&&first==1){
            head=QH[i];
            tail=QT[i];
            first=0;
        }
        if(QH[i]!=NULL&&first==0){
            tail->next=QT[i];
            tail=QT[i];
        }
    }

    cout<<endl<<"show all elements:"<<endl;
    p=head;
    while(p!=NULL){
        cout<<p->data<<"\t";
        p=p->next;
    }
    cout<<endl;
}

int main(int argc, char *argv[])
{
    //QCoreApplication a(argc, argv);

    int i;
    QNode*QH[MaxQNode],*QT[MaxQNode];
    for(i=0;i<MaxQNode;i++){
        QH[i]=QT[i]=NULL;
    }
    Create(QH,QT);
    Link(QH,QT);

    return 0;
    //return a.exec();
}
